<template>
	<CustomizePage :pageid="pageid" :input-data="inputData" />
</template>

<script lang="ts">
import { ElMessage } from 'element-plus';
import { useRouter } from 'vue-router';
import CustomizePage from '/@/components/Linxyun/custom/CustomizePage/index.vue';
export default defineComponent({
	// name: 'customizepage',
	components: {
		CustomizePage,
	},
	setup() {
		const router = useRouter();
		const state = reactive<any>({
			pageid: 0,
			inputData: {},
		});

		onBeforeMount(() => {
			console.log('customizepage onMounted query: ', router.currentRoute.value.query);
			console.log('customizepage onMounted params: ', router.currentRoute.value.params);
			console.log('customizepage onMounted path: ', router.currentRoute.value.path);
			const query = router.currentRoute.value.query;
			let UrlParams = {};
			if (query.from) {
				const storage = sessionStorage.getItem(query.from as string);
				if (storage) {
					UrlParams = JSON.parse(storage);
				}
			}
			state.inputData = { UrlParams: UrlParams || {} };
			console.log('customizepage onMounted inputdata: ', state.inputData);
			const pathPageIdIdx = router.currentRoute.value.path.indexOf('PageID=');
			if (pathPageIdIdx < 0) {
				ElMessage({
					message: '页面错误，ErrorCode: 880320',
					type: 'error',
					duration: BASE_API.MSG_SHOW_TIME,
				});
				// 退回到上一个页面。
				router.back();
			}

			let pathPageIdEndIdx = router.currentRoute.value.path.indexOf('&', pathPageIdIdx + 1);
			if (pathPageIdEndIdx <= 0) {
				pathPageIdEndIdx = router.currentRoute.value.path.length;
			}
			const pageId = router.currentRoute.value.path.substring(pathPageIdIdx + 7, pathPageIdEndIdx);
			if (!pageId) {
				ElMessage({
					message: '页面错误，ErrorCode: 880320',
					type: 'error',
					duration: BASE_API.MSG_SHOW_TIME,
				});
				// 退回到上一个页面。
				router.back();
			}
			state.pageid = Number(pageId);
			if (isNaN(state.pageid)) {
				ElMessage({
					message: '页面错误，ErrorCode: 880320',
					type: 'error',
					duration: BASE_API.MSG_SHOW_TIME,
				});
				// 退回到上一个页面。
				router.back();
			}
			console.log('customizepage onMounted pageid: ', state.pageid);
		});

		return {
			...toRefs(state),
		};
	},
});
</script>
